<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <title>文本操作：更新内容/更新内容并清空历史栈/插入内容/更新选中内容/删除选中内容/设置预览区域内容 - Vditor</title>
    <meta name="robots" content="index,follow,archive">
    <meta name="description"
          content="Vditor - 易于使用的 Markdown 编辑器，为适配不同的应用场景而生。它使用 TypeScript 实现，支持原生 JavaScript、Vue、React、Angular，提供桌面版。"/>
    <meta name="copyright" content="B3log"/>
    <link rel="canonical" href="https://b3log.org/vditor/demo/method-CRUD.html">
    <link rel="apple-touch-icon" href="https://b3log.org/images/brand/vditor-128.png">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta http-equiv="Window-target" content="_top"/>
    <link rel="icon" type="image/png" href="https://b3log.org/images/brand/vditor-128.png"/>
    <link rel="shortcut icon" type="image/x-icon" href="https://b3log.org/images/brand/vditor-512.png"/>
    <link type="text/css" rel="stylesheet" href="https://b3log.org/css/base.css" charset="utf-8"/>

    <meta property="og:locale" content="zh_CN"/>
    <meta property="og:title" content="文本操作：更新内容/更新内容并清空历史栈/插入内容/更新选中内容/删除选中内容/设置预览区域内容 - Vditor"/>
    <meta property="og:description"
          content="Vditor - 易于使用的 Markdown 编辑器，为适配不同的应用场景而生。它使用 TypeScript 实现，支持原生 JavaScript、Vue、React、Angular，提供桌面版。"/>
    <meta property="og:image" content="https://b3log.org/images/brand/vditor-128.png"/>
    <meta property="og:url" content="https://b3log.org/vditor"/>
    <meta property="og:site_name" content="B3log"/>
    <meta name="twitter:card" content="summary_large_image"/>
    <meta name="twitter:description"
          content="Vditor - 易于使用的 Markdown 编辑器，为适配不同的应用场景而生。它使用 TypeScript 实现，支持原生 JavaScript、Vue、React、Angular，提供桌面版。"/>
    <meta name="twitter:title" content="文本操作：更新内容/更新内容并清空历史栈/插入内容/更新选中内容/删除选中内容/设置预览区域内容 - Vditor"/>
    <meta name="twitter:image" content="https://b3log.org/images/brand/vditor-128.png"/>
    <meta name="twitter:url" content="https://b3log.org/vditor"/>
    <meta name="twitter:site" content="@b3logos"/>
    <meta name="twitter:creator" content="@b3logos"/>
    <script src="https://b3log.org/vditor/vditor.js" defer></script>
    <style>
        .header {
            background-color: #fff;
            box-shadow: rgba(0, 0, 0, 0.05) 0 1px 7px;
            border-bottom: 1px solid #e1e4e8;
        }
    </style>
</head>
<body>
<div class="header fn-clear">
    <a class="header-logo" href="https://b3log.org/vditor">
        <img src="https://b3log.org/images/brand/vditor-128.png">
        <h1>Vditor</h1>
    </a>
    <div class="fn-clear">
        <a class="header-a" href="https://ld246.com/tag/vditor" target="_blank">社区</a>
        <a class="header-a header-red" target="_blank" href="https://ld246.com/article/1549638745630">API</a>
        <a class="header-a header-green current" href="index.html">Demo</a>
        <a class="header-a header-yellow" href="https://ld246.com/sponsor" target="_blank">成为赞助者</a>
    </div>
</div>
<div class="wrapper">
    <div class="fn-50"></div>
    相关 <a href="https://ld246.com/article/1549638745630#methods" target="_blank">API</a>：
    insertValue()，setValue()，deleteValue()，updateValue()，renderPreview()
    <div class="fn-50"></div>
    <div>
        <button class="btn btn--small" onclick="vditor.setValue('wysiwyg = Typora');updateCode(this, 'vditor.setValue(\'wysiwyg = Typora\');')">更新内容</button> &nbsp;
        <button class="btn btn--small" onclick="vditor.setValue('wysiwyg = Typora', true);updateCode(this, 'vditor.setValue(\'wysiwyg = Typora\', true);')">更新内容并清空历史栈</button> &nbsp;
        <button class="btn btn--small" onclick="vditor.insertValue('Vditor ');updateCode(this, 'vditor.insertValue(\'Vditor \');')">在光标位置插入内容</button> &nbsp;
        <button class="btn btn--small" onclick="vditor.deleteValue();updateCode(this, 'vditor.deleteValue();')">删除选中内容</button> &nbsp;
        <button class="btn btn--small" onclick="vditor.updateValue('Vditor');updateCode(this, 'vditor.updateValue(\'Vditor\');')">更新选中内容</button> &nbsp;
        <button class="btn btn--small" onclick="vditor.renderPreview('ir 适合大屏下的 Markdown 编辑');updateCode(this, 'vditor.renderPreview(\'ir 适合大屏下的 Markdown 编辑\');')">设置预览区域内容</button> &nbsp;
    </div>
    <div id="vditor"></div>
    <div id="vditorDemoCode" class="vditor-reset">
        <pre><code class="javascript">new Vditor('vditor', {
  mode: 'sv',
  cache: {
    enable: false
  },
  height: 360,
  value: '所见即所得模式对不熟悉 Markdown 的用户较为友好，熟悉 Markdown 的话也可以无缝使用。'
})
</code></pre>
    </div>
    <div class="fn-100"></div>
    <div class="fn-clear">
        <h2 class="fn-left">参与讨论</h2>
        <span class="fn-right" style="line-height: 36px" id="commentCnt"></span>
    </div>
    <div class="fn-50"></div>
    <div id="vditorComments"></div>
    <div class="fn-100"></div>
</div>
<!-- end main -->

<div class="footer">
    <div class="wrapper fn-clear">
        <a href="https://b3log.org">首页</a> &nbsp; &nbsp;
        <a href="https://ld246.com" target="_blank">社区</a> &nbsp; &nbsp;
        <a href="https://b3log.org/brand-marking.html">品牌标识</a> &nbsp; &nbsp;
        <a href="https://ld246.com/sponsor" target="_blank">成为赞助者</a>
        <div class="fn-right">
            <a href="https://beian.miit.gov.cn/" target="_blank">滇ICP备14007358号-1</a> &nbsp; &nbsp;
            © 2023 云南链滴科技有限公司
        </div>
    </div>
</div>
<script>
    let vditor
    vditorScript = () => {
      vditor = new Vditor('vditor', {
        mode: 'sv',
        cache: {
          enable: false
        },
        height: 360,
        value: '所见即所得模式对不熟悉 Markdown 的用户较为友好，熟悉 Markdown 的话也可以无缝使用。'
      })
    }
</script>
</body>
</html>
